<?

/***************************************************************************
 Jupiter Content System @ Jupiterportal.com
 Copyright (C) 2005 Cosmin Flavius (highstrike@gmail.com)

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 More Info About The Licence At http://www.gnu.org/copyleft/gpl.html
****************************************************************************/

//-----------------------------------------------------------------
//  Start action switch
//-----------------------------------------------------------------

switch($a)
{
	//-----------------------------------------------------------------
	//  Add events case
	//-----------------------------------------------------------------

	case 1:

		//-----------------------------------------------------------------
		//  Check if he has acces
		//-----------------------------------------------------------------

		if(isset($is_loged_in))
		{
            $cat = $db->getLine("SELECT cat FROM forum_subcat WHERE id = '$scat'");
                
            if(!$cat)
            {
                header("location: $PHP_SELF?n=modules/events");
                exit;
            }
            else $cat = $cat['cat'];
            
			//-----------------------------------------------------------------
			//  BBcode check
			//-----------------------------------------------------------------

			for ($i = 1; $i <= 5; $i++) if(check_tag_order($sendmessage) == $i) { header("location: $PHP_SELF?n=modules/events&a=4&d=$eventdaya&m=$eventmontha&i=9$i"); exit; }

			//-----------------------------------------------------------------
			//  Make time for start and end
			//-----------------------------------------------------------------

			if($eventstartah == 0 || $eventstartam == 0 || $eventendah == 0 || $eventendam == 0)
			{
				$eventstarta = 0;
				$eventenda = 0;
			}
			else
			{
				if($eventstartam == 1) $eventstartam = 0;
				if($eventstartam == 2) $eventstartam = 15;
				if($eventstartam == 3) $eventstartam = 30;
				if($eventstartam == 4) $eventstartam = 45;

				if($eventendam == 1) $eventendam = 0;
				if($eventendam == 2) $eventendam = 15;
				if($eventendam == 3) $eventendam = 30;
				if($eventendam == 4) $eventendam = 45;

				$eventstarta = mktime($eventstartah, $eventstartam, 0, $eventmontha, $eventdaya, $eventyeara);
				$eventenda = mktime($eventendah, $eventendam, 0, $eventmontha, $eventdaya, $eventyeara);
			}

			//-----------------------------------------------------------------
			//  Take care of some things
			//-----------------------------------------------------------------

            $eventtitle = trim(jcm_stripslashes(do_censor(jcm_htmlspecialchars($eventtitle))));
			$sendmessage = jcm_htmlspecialchars(jcm_linebreaks(trim(jcm_stripslashes($sendmessage))));
			if($overflow = check_tag_order($sendmessage)) $sendmessage = substr($sendmessage, 0, $overflow[0]).substr($sendmessage, $overflow[1], (strlen($sendmessage) - $overflow[0]));
            $eventmessage = $sendmessage;
            
            //-----------------------------------------------------------------
			//  Start Checks
			//-----------------------------------------------------------------

			$user = $db->getLine("SELECT id, username, email, forumposts ".
                                 "FROM users WHERE id = '".$_SESSION['id'].
                                 "' AND username = '".$_SESSION['username'].
                                 "'");
                                 
			$id = $user['id'];
			$username = $user['username'];
			$email = $user['email'];
			$topic_type = 3;
			$author_reg = 2;
			
			//Check if titleevent exists when adding a new event.
			//if(!$topic_name){ header("location: $PHP_SELF?n=modules/forum&a=4&d=$d&o=$o&i=99"); exit; }

			$topic_name = $eventtitle;
			$sendmessage = NULL;
			$topic_language = $eventlanguage;

			//-----------------------------------------------------------------
			//  Write in database
			//-----------------------------------------------------------------

			$db->insertRow("forum_topics", array("cat" => $cat,
                           "subcat" => $scat, "date" => time(),
                           "name" => $topic_name,
                           "author_reg" => $author_reg,
                           "author_id" => $id, "author_user" => $username,
                           "author_email" => $email, "mode" => $topic_type,
                           "ip" => find_ip()));
                              
			$check_topic = $db->getLine("SELECT * FROM forum_topics WHERE cat = '$cat' AND subcat = '$scat' ORDER BY id DESC");
			
			$db->insertRow("forum_replies", array('cat' => $cat,
                           "subcat" => $scat,
                           "topic" => $check_topic['id'], "date" => time(),
                           "user_reg" => $author_reg, "user_id" => $id,
                           "user_user" => $username, "user_email" => $email,
                           "message" => $sendmessage, "ip" => find_ip()));
                             
			$check_reply = $db->getLine("SELECT * FROM forum_replies ORDER BY id DESC");
			
			$db->updateRow("forum_subcat", array(
                           "lastpost_location" => $check_reply['id'],
                           "lastpost_date" => time(),
                           "lastpost_reg" => $author_reg,
                           "lastpost_id" => $id,
                           "lastpost_user" => $username,
                           "lastpost_email" => $email), "id = '$scat'");
                             
			$db->updateRow("forum_topics", array(
                           "lastpost_location" => $check_reply['id'],
                           "lastpost_date" => time(),
                           "lastpost_reg" => $author_reg,
                           "lastpost_id" => $id,
                           "lastpost_user" => $username,
                           "lastpost_email" => $email,
                           "language" => $topic_language),
                           "id = {$check_topic['id']}");
                             
			$check_topics = $db->getInfo_countRows("forum_topics", "cat = '$cat' AND subcat = '$scat' AND type != '3'");
			$check_replies = $db->getInfo_countRows("forum_replies","cat = '$cat' AND subcat = '$scat'");
			
            $db->updateRow("forum_subcat", array("topics" => $check_topics,
                           "replies" => $check_replies), "id = '$scat'");				

			$plus_forumposts = $user['forumposts'] + 1;
			$db->updateRow("users", array("forumposts" => $plus_forumposts),
                           "id = {$user['id']}");
            
			//-----------------------------------------------------------------
			//  Add in database
			//-----------------------------------------------------------------

			$db->insertRow("events", array("user_id" => $_SESSION['id'],
            "user_user" => $_SESSION['username'],
            "day" => $eventdaya,
            "month" => $eventmontha,
            "year" => $eventyeara,
            "start" => $eventstarta,
            "end" => $eventenda,
            "message" => $eventmessage,
            "title" => $eventtitle,
            "location" => $eventlocation,
            "language" => $eventlanguage,
            "topic" => $check_topic['id']));
            
			//-----------------------------------------------------------------
			//  Redirect when finished
			//-----------------------------------------------------------------
			
			header("location: $PHP_SELF?n=modules/forum&a=3&d=$cat&o=$scat&q={$check_topic['id']}&i={$check_reply['id']}");
		}

	break;

	//-----------------------------------------------------------------
	//  Edit events case
	//-----------------------------------------------------------------

	case 2:

		//-----------------------------------------------------------------
		//  Check if he has acces
		//-----------------------------------------------------------------

		if(isset($is_moderator) || isset($is_administrator) || isset($is_webmaster))
		{
			//-----------------------------------------------------------------
			//  BBcode check
			//-----------------------------------------------------------------

			for ($i = 1; $i <= 5; $i++) if(check_tag_order($sendmessage) == $i) { header("location: $PHP_SELF?n=modules/events&a=5&d=$eventdaye&m=$eventmonthe&o=$o&i=9$i"); exit; }

			//-----------------------------------------------------------------
			//  Make time for start and end
			//-----------------------------------------------------------------

			if($eventstarteh == 0 || $eventstartem == 0 || $eventendeh == 0 || $eventendem == 0)
			{
				$eventstarte = 0;
				$eventende = 0;
			}
			else
			{
				if($eventstartem == 1) $eventstartem = 0;
				if($eventstartem == 2) $eventstartem = 15;
				if($eventstartem == 3) $eventstartem = 30;
				if($eventstartem == 4) $eventstartem = 45;

				if($eventendem == 1) $eventendem = 0;
				if($eventendem == 2) $eventendem = 15;
				if($eventendem == 3) $eventendem = 30;
				if($eventendem == 4) $eventendem = 45;

				$eventstarte = mktime($eventstarteh, $eventstartem, 0, $eventmonthe, $eventdaye, $eventyeare);
				$eventende = mktime($eventendeh, $eventendem, 0, $eventmonthe, $eventdaye, $eventyeare);
			}

			//-----------------------------------------------------------------
			//  Take care of some things
			//-----------------------------------------------------------------

			$sendmessage = jcm_linebreaks(trim(jcm_stripslashes($sendmessage)));
			if($overflow = check_tag_order($sendmessage)) $sendmessage = substr($sendmessage, 0, $overflow[0]).substr($sendmessage, $overflow[1], (strlen($sendmessage) - $overflow[0]));

			//-----------------------------------------------------------------
			//  Update the database
			//-----------------------------------------------------------------

			$db->updateRow("events",array('day' => ''.$eventdaye.'','month' => ''.$eventmonthe.'','year' => ''.$eventyeare.'','start' => ''.$eventstarte.'','end' => ''.$eventende.'','message' => ''.$sendmessage.'','title'=> ''.$eventtitle.'','location' => ''.$eventlocation.'','language' => ''.$eventlanguage.''),"id = $o");

			//-----------------------------------------------------------------
			//  Redirect when finished
			//-----------------------------------------------------------------

			header("location: $PHP_SELF?n=modules/events&d=$eventdaye&m=$eventmonthe&i=45");
		}

	break;

	//-----------------------------------------------------------------
	//  Delete events case
	//-----------------------------------------------------------------

	case 3:

		//-----------------------------------------------------------------
		//  Check if he has acces
		//-----------------------------------------------------------------

		if(isset($is_moderator) || isset($is_administrator) || isset($is_webmaster))
		{
			//-----------------------------------------------------------------
			//  Delete from the database
			//-----------------------------------------------------------------

			$db->deleteRow("events","id = '$o'");

			//-----------------------------------------------------------------
			//  Redirect when finished
			//-----------------------------------------------------------------

			header("location: $PHP_SELF?n=modules/events&d=$d&m=$m&i=46");
		}

	break;

	//-----------------------------------------------------------------
	//  View Form for adding events case
	//-----------------------------------------------------------------

	case 4:

		//-----------------------------------------------------------------
		//  Check if he has acces
		//-----------------------------------------------------------------

		if(isset($is_loged_in))
		{
			?>
				<form method="post" action="<?= $PHP_SELF ?>?n=modules/events" name="addevent">
				<table class="main" cellspacing="1" cellpadding="4" width="100%">
				<col width="25%"><col width="75%">
				<tr class="head"> 
				<td colspan="2" class="head"><?= $language['Events add/edit title'] ?></td>
				</tr>
				<tr>
				<td class="con1" valign="middle"><?= $language['Events add/edit desc1'] ?></td>
				<td><input type='text' name="eventtitle" class="box" style="width:100%"></td>
				</tr>
				<tr>
				<td class="con1" valign="middle"><?= $language['Events add/edit desc'] ?></td>
				<td class="con1" valign="bottom"><?= $language['Events add/edit desc2'] ?> 
				<select name="eventdaya" class="textbox" style="width:14%">
			<?
			for ($i = 1; $i <= 31; $i++)
			{
				if(isset($d))
				{
					if($i == $d) $selected = "selected";
					else $selected = "";
				}

				echo "<option value='$i' $selected>$i</option>\n";
			}
			?>
				</select> <?= $language['Events add/edit desc3'] ?> <select name="eventmontha" class="box" style="width:32%">
			<?
			for ($i = 1; $i <= 12; $i++)
			{
				if(isset($m))
				{
					if($i == $m) $selected = "selected";
					else $selected = "";
				}

				echo "<option value='$i' $selected>{$months[$i]}</option>\n";
			}
			?>
				</select> <?= $language['Events add/edit desc4'] ?> <select name="eventyeara" class="box" style="width:26%">
			<?
			for ($i = date("Y"); $i <= date("Y"); $i++)
			{
				if($i == date('Y')) $selected = "selected";
				else $selected = "";

				echo "<option value='$i' $selected>$i</option>\n";
			}
            
			?>
				</select>
				<tr>
				<td class="con1" valign="middle"><?= $language['Events add/edit desc5'] ?></td>
				<td class="con1" valign="bottom"><?= $language['Events add/edit desc6'] ?> <select name="eventstartah" class="box" style="width:45px"><option value="0" selected></option><? for($i = 1; $i <= 24; $i++){ echo "<option value='$i'>$i</option>\n"; } ?></select>:<select name="eventstartam" class="box" style="width:45px"><option value="0" selected></option><option value="1">00</option><option value="2">15</option><option value="3">30</option><option value="4">45</option></select> / <select name="eventendah" class="box" style="width:45px"><option value="0" selected></option><? for($i = 1; $i <= 24; $i++){ echo "<option value='$i'>$i</option>\n"; } ?></select>:<select name="eventendam" class="box" style="width:45px"><option value="0" selected></option><option value="1">00</option><option value="2">15</option><option value="3">30</option><option value="4">45</option></select> <?= $language['Events add/edit desc7'] ?></td>
				</tr>
				<tr>
				<td class="con1" valign="middle"><?= $language['Events view title4'] ?></td>
				<td><input type='text' name="eventlocation" class="box" style="width:40%" ></td>
				</tr>
				<tr>
				<td class="con1" valign="middle"><?= $language['Events add/edit desc12'] ?></td>
				<td><input type='text' name="eventlanguage" class="box" style="width:10%" ></td>
				</tr>
				<tr>
				<td class="con1" valign="top"><?= "{$language['Events add/edit desc8']}".dis_bb_em()."" ?></td>
				<td class="con1" valign="middle"><textarea style="width:100%; height:70px;" class="box" name="sendmessage" ></textarea></td>
				</tr>
				<tr>
				<td class="con1"><input type="button" style="width:100" class="box" value="<?= $language['Events add/edit desc9'] ?>" onClick="window.history.go(-1);" ></td>
				<td class="con1" align="right"><input type="submit" style="width:100" class="box" value="<?= $language['Events add/edit desc10'] ?>" ></td>
				</tr>
                <input type='hidden' name='scat' value='<?=$s?>'>
				<input type="hidden" name="a" value="1">
				</table></form>
			<?
		}

	break;

	//-----------------------------------------------------------------
	//  View Form for editing events case
	//-----------------------------------------------------------------

	case 5:

		//-----------------------------------------------------------------
		//  Check if he has acces
		//-----------------------------------------------------------------

		if(isset($is_loged_in))
		{
			//-----------------------------------------------------------------
			//  Look into the database for the event
			//-----------------------------------------------------------------
			
			$event_info = $db->getLine("SELECT * FROM events WHERE id = '$o'") ?>
				<form method="post" action="<?= $PHP_SELF ?>?n=modules/events" name="editevent">
				<table class="main" cellspacing="1" cellpadding="4" width="100%">
				<col width="25%"><col width="75%">
				<tr class="head"> 
				<td colspan="2" class="head"><?= $language['Events add/edit title2'] ?></td>
				</tr>
				<tr>
				<td class="con1" valign="middle"><?= $language['Events add/edit desc1'] ?></td>
				<td><input type='text' name="eventtitle" class="box" style="width:100%" value="<?= $event_info['title'] ?>"></td>
				</tr>
				<tr>
				<tr>
				<td class="con1" valign="middle"><?= $language['Events add/edit desc'] ?></td>
				<td class="con1" valign="bottom"><?= $language['Events add/edit desc2'] ?> 
				<select name="eventdaye" class="box" style="width:14%">
			<?
			for ($i = 1; $i <= 31; $i++)
			{
				if (isset($d) && ($i == $d))
                    $selected = "selected";	
                else
                    $selected = "";
				echo "<option value='$i' $selected>$i</option>\n";
			}
			
			echo "</select> {$language['Events add/edit desc3']} ".
            "<select name='eventmonthe' class='box' style='width:32%'>";
            
			for ($i = 1; $i <= 12; $i++)
			{
				if (isset($m) && ($i == $m))
                    $selected = "selected";
				else
                    $selected = "";
				echo "<option value='$i' $selected>{$months[$i]}</option>\n";
			}
			
			echo "</select> {$language['Events add/edit desc4']} ".
            "<select name='eventyeare' class='box' style='width:26%'>";
            
			for ($i = date("Y"); $i >= 1970; $i--)
			{
				if (isset($ye) && ($i == $ye))
                    $selected = "selected";
				else
                    $selected = "";

				echo "<option value='$i' $selected>$i</option>\n";
			}
			?>
				</select>
				<tr>
				<td class="con1" valign="middle"><?= $language['Events add/edit desc5'] ?></td>
				<td class="con1" valign="bottom"><?= $language['Events add/edit desc6'] ?> <select name="eventstarteh" class="box" style="width:45px">
			<?
			if($event_info['start'] != 0)
				echo "<option value='0'></option>";
			else
				echo "<option value='0' selected></option>";

			for($i = 1; $i <= 24; $i++)
			{
				if($event_info['start'] != 0)
				{
					if ($i == date("H",$event_info['start']))
                        $selected = "selected";
					else
                        $selected = "";

					echo "<option value='$i' $selected>$i</option>\n";
				}
				else
					echo "<option value='$i'>$i</option>\n";
			}
			
			echo "</select>:<select name='eventstartem' class='box' ".
            "style='width:45px'>";
			
			if($event_info['start'] != 0)
			{
				if(date("i",$event_info['start']) == 0) echo "<option value='0' selected></option>"; else echo "<option value='0'></option>";
				if(date("i",$event_info['start']) == 00) echo "<option value='1' selected>00</option>"; else echo "<option value='1'>00</option>";
				if(date("i",$event_info['start']) == 15) echo "<option value='2' selected>15</option>"; else echo "<option value='2'>15</option>";
				if(date("i",$event_info['start']) == 30) echo "<option value='3' selected>30</option>"; else echo "<option value='3'>30</option>";
				if(date("i",$event_info['start']) == 45) echo "<option value='4' selected>45</option>"; else echo "<option value='4'>45</option>";
			}
			else echo "<option value='0' selected></option><option value='1'>00</option><option value='2'>15</option><option value='3'>30</option><option value='4'>45</option>" ?>
				</select> / <select name="eventendeh" class="box" style="width:45px">
			<?
			if($event_info['end'] != 0)
				echo "<option value='0'></option>";
			else
				echo "<option value='0' selected></option>";

			for($i = 1; $i <= 24; $i++)
			{
				if($event_info['end'] != 0)
				{
					if($i == date("H",$event_info['end'])) $selected = "selected";
					else $selected = "";

					echo "<option value='$i' $selected>$i</option>\n";
				}
				else
					echo "<option value='$i'>$i</option>\n";
			}
			?>
				</select>:<select name="eventendem" class="box" style="width:45px">
			<?
			if($event_info['end'] != 0)
			{
				if(date("i",$event_info['end']) == 0) echo "<option value='0' selected></option>"; else echo "<option value='0'></option>";
				if(date("i",$event_info['end']) == 00) echo "<option value='1' selected>00</option>"; else echo "<option value='1'>00</option>";
				if(date("i",$event_info['end']) == 15) echo "<option value='2' selected>15</option>"; else echo "<option value='2'>15</option>";
				if(date("i",$event_info['end']) == 30) echo "<option value='3' selected>30</option>"; else echo "<option value='3'>30</option>";
				if(date("i",$event_info['end']) == 45) echo "<option value='4' selected>45</option>"; else echo "<option value='4'>45</option>";
			}
			else echo "<option value='0' selected></option><option value='1'>00</option><option value='2'>15</option><option value='3'>30</option><option value='4'>45</option>" ?>
				</select> <?= $language['Events add/edit desc7'] ?></td>
				</tr>
				<tr>
				<td class="con1" valign="middle"><?= $language['Events view title4'] ?></td>
				<td><input type='text' name="eventlocation" class="box" style="width:40%" value="<?= $event_info['location'] ?>"></td>
				</tr>
				<tr>
				<td class="con1" valign="middle"><?= $language['Events add/edit desc12'] ?></td>
				<td><input type='text' name="eventlanguage" class="box" style="width:10%" value="<?= $event_info['language'] ?>"></td>
				</tr>
				<tr>
				<td class="con1" valign="top"><?= "{$language['Events add/edit desc8']}".dis_bb_em()."" ?></td>
				<td class="con1" valign="bottom"><textarea style="width:100%; height:70px;" class="box" name="sendmessage" ><?= $event_info['message'] ?></textarea></td>
				</tr>
				<tr>
				<td class="con1"><input type="button" style="width:100" class="box" value="<?= $language['Events add/edit desc9'] ?>" onClick="window.history.go(-1);" ></td>
				<td class="con1" align="right"><input type="submit" style="width:100" class="box" value="<?= $language['Events add/edit desc11'] ?>" ></td>
				</tr>
				<input type="hidden" name="a" value="2">
				<input type="hidden" name="o" value="<?= $event_info['id'] ?>">
				</table></form>
			<?
		}

	break;

	//-----------------------------------------------------------------
	//  View events default case
	//-----------------------------------------------------------------

	default:

		//-----------------------------------------------------------------
		//  Load the events row
		//-----------------------------------------------------------------
		
		global $ye;
		if ($ye == NULL)
            $year = date('Y');
		else $year = $ye;
		
		$months = array("",$language['Name month'],  $language['Name month2'],
                           $language['Name month3'], $language['Name month4'],
                           $language['Name month5'], $language['Name month6'],
                           $language['Name month7'], $language['Name month8'],
                           $language['Name month9'], $language['Name month10'],
                           $language['Name month11'],$language['Name month12']);
        
        $events_db = $db->getTable("
        SELECT e.id, e.type, e.user_id, e.user_user, e.start, e.day, e.month, ".
        "e.year, e.end, e.message, e.location, e.title, u.age ".
        "FROM events AS e LEFT JOIN users AS u ON e.user_id = u.id ".
        "WHERE day = '$d' AND month = '$m' AND year = '$year' ".
        "ORDER BY start ASC,type DESC");
        
        $layout = "";
        
		foreach($events_db as $idx=>$event)
		{
			//-----------------------------------------------------------------
			//  Figure out the start and end
			//-----------------------------------------------------------------

			if($event['type'] == "normal")
			{
				if($event['year'] == $year)
				{
					//-----------------------------------------------------------------
					//  Code Layout
					//-----------------------------------------------------------------
                    
                    $layout .=
                    "<tr><td valign='middle' class='con1'>{$event['day']} ".
                    "{$language['Calendar of']} {$months[$event['month']]}".
                    "<br>";
                
                    if ($event['start'] != 0 || $event['end'] != 0)
                        $layout .= date("H:i", $event['start'])." - ".
                                   date("H:i", $event['end'])."</td>";
                    else
                        $layout .= "{$language['Events view desc2']}</td>";
				}
			}
			else $layout .= "<tr><td class='con1'>{$language['Events view desc2']}</td>";

			//-----------------------------------------------------------------
			//  Figure out if it's a bday or just event
			//-----------------------------------------------------------------

			if($event['type'] == "normal")
			{
				if($event['year'] == $year)
				{
					//-----------------------------------------------------------------
					//  Code Layout
					//-----------------------------------------------------------------

					// Google Date hack
					
					if ($d <10) $d = "0".$d;
					
					if ($event['start'] != 0 || $event['end'] != 0)
						$google_date = $year.$m.$d."T".date("Hi",
                                       $event['start'])."00Z/".
                                       $year.$m.$d."T".date("Hi",
                                       $event['end'])."00Z";
                    else
						$google_date = $year.$m.$d."T000000Z/".
                                       $year.$m.$d."T210000Z";
					
                    // End of Google Date hack
					
                    $layout .= "<td class='con1'>{$event['location']}</td>".
                               "<td class='con1'><a href='$PHP_SELF?n=".
                               "modules/users&a=1&d={$event['user_id']}'>".
                               $event['user_user']."</a>: ".
                               parse_message($event['message'])."</td>";
					
                    if (isset($is_moderator) || isset($is_administrator) ||
                        isset($is_webmaster))
                        $layout .= "<td valign='bottom' class='con1'>".
                                   "<a href='$PHP_SELF?n=modules/events&a=5&d=".
                                   "$d&m=$m&o={$event['id']}'><img src='".
                                   "templates/$template/images/buttons/".
                                   "edit.gif' border='0' alt='".
                                   $language['Events view desc8']."'></a>".
                                   "<a href='$PHP_SELF?n=modules/events&a=3&d=".
                                   "$d&m=$m&o={$event['id']}'><img src='".
                                   "templates/$template/images/buttons/".
                                   "delete.gif' border='0' alt='".
                                   $language['Events view desc9']."'></a></td>".
                                   "</tr>";
                    else $layout .= "<td valign='top' class ='con1'>".
                                    "<a href='http://www.google.com/calendar/".
                                    "event?action=TEMPLATE&text=".
                                    parse_message($event['title']).
                                    "&dates=$google_date&details=".
                                    parse_message($event['message']).
                                    "&location=".
                                    parse_message($event['location'])."&trp=".
                                    "false&sprop=&sprop=name:Galicia%20Rol' ".
                                    "target='_blank'><img src='http://".
                                    "www.google.com/calendar/images/ext/".
                                    "gc_button6_es.gif' border=0></a>".
                                    "<br>".
                                    "<a href='http://www.twitter.com/home?".
                                    "status=".str_replace(" ", "+",
                                    parse_message($event['title'])).",+el+".
                                    parse_message($event['day'])."/".
                                    parse_message($event['month'])."/".
                                    parse_message($event['year'])."+en+".
                                    str_replace(" ", "+",
                                    parse_message($event['location'])).
                                    ".+M&aacute;s+info+en+http://".
                                    "www.galiciarol.org/'><img src='images/".
                                    "twitter.jpg' border='0'></a></td></tr>";
				}
			}
			else
			{
				//-----------------------------------------------------------------
				//  Calculate Age
				//-----------------------------------------------------------------

				if($event['day'] > date("j") || $event['month'] > date("n"))
				{
					$surplus = (date("Y") + 1) - date("Y");
					$bday_age = find_age("{$event['age']}", $surplus);
				}
				else
					$bday_age = find_age("{$event['age']}");

				//-----------------------------------------------------------------
				//  Calculate Time for bday
				//-----------------------------------------------------------------

				if($event['day'] == date("j") && $event['month'] == date("n"))
				{
					$bday_date_1 = $language['Events view desc3'];
					$bday_date_2 = $language['Events view desc4'];
					$bday_date_3 = $language['Events view desc5'];
				}
				else
				{
					$bday_date_1 = NULL;
					$bday_date_2 = $language['Events view desc6'];
					$bday_date_3 = "{$language['Events view desc7']} ".
                                   "{$event['day']} {$language['Calendar of']}".
                                   " {$months[$event['month']]}";
				}

				//-----------------------------------------------------------------
				//  Code Layout
				//-----------------------------------------------------------------

				$layout .= "<td class='con1'></td><td class='con1'>$bday_date_1 <a href='$PHP_SELF?n=modules/users&a=1&d={$event['user_id']}'>{$event['user_user']}</a> $bday_date_2 $bday_age $bday_date_3</td>\n";

				if(isset($is_moderator) || isset($is_administrator) || isset($is_webmaster)) $layout .= "<td valign='bottom' class='con1'><img src='templates/$template/images/buttons/noedit.gif' border='0' alt='{$language['Events view desc10']}'><img src='templates/$template/images/buttons/nodelete.gif' border='0' alt='{$language['Events view desc11']}'></td></tr>"; else $layout .= "</tr>";
			}
		}

		//-----------------------------------------------------------------
		//  If no event that day, show error
		//-----------------------------------------------------------------

		if($events_db == FALSE) $layout .= "<tr><td class='con1' colspan='3'>{$language['Events view desc']}</td></tr>";

		//-----------------------------------------------------------------
		//  Start Layout
		//-----------------------------------------------------------------
			
        echo
        "<table class='main' cellspacing='1' cellpadding='4'>".
        "<tr class='head'>".
        "<td colspan='4'>{$language['Events view title']}</td></tr>".
        "<tr><td colspan='2'><a href='index.php?n=modules/calendar'>".
        "<b>{$language['Calendar view calendar']}</a></b></td>".
        "<td colspan='2' align='right'><a href='index.php?n=modules/calendar".
        "&a=1'><b>{$language['Calendar view list']}</a></b></td>".
        "</tr>".
        "<tr class='bottom'>".
        "<td width='15%'>{$language['Events view title2']}</td>".
        "<td width='15%'>{$language['Events view title4']}</td>".
        "<td width='82%'>{$language['Events view title3']}</td>".
        "<td width='1%'>{$language['Events view title5']}</td>".
        "</tr>".$layout."</table>";
}

?>
